import 'package:flutter/material.dart';

class BuyButton extends StatelessWidget {
  const BuyButton({
    Key? key,
    this.text = '',
    this.fontSize = 14,
    this.textColor,
    this.disabledTextColor,
    this.backgroundColor,
    this.disabledBackgroundColor,
    this.minHeight = 40.0,
    this.minWidth = double.infinity,
    this.padding = const EdgeInsets.symmetric(horizontal: 16.0),
    this.radius = 20.0,
    this.side = BorderSide.none,
    this.isGradient = true,
    this.gradient = const LinearGradient(
      colors: [
        Color(0xFFFF8400),
        Color(0xFFFE5200),
      ],
    ),
    this.unSelectedGradient = const LinearGradient(
      colors: [
        Color(0xFFFFB565),
        Color(0xFFFF9562),
      ],
    ),
    required this.onPressed,
    this.leftOrRight = true,
  }) : super(key: key);

  final String text;
  final double fontSize;
  final Color? textColor;
  final Color? disabledTextColor;
  final Color? backgroundColor;
  final Color? disabledBackgroundColor;
  final double? minHeight;
  final double? minWidth;
  final VoidCallback? onPressed;
  final EdgeInsetsGeometry padding;
  final double radius;
  final BorderSide side;
  final bool isGradient;
  final LinearGradient gradient;
  final LinearGradient unSelectedGradient;
  final bool leftOrRight;

  @override
  Widget build(BuildContext context) {
    return Container(
      height: minHeight,
      width: minWidth,
      decoration: BoxDecoration(
        gradient: onPressed != null ? gradient : unSelectedGradient,
        borderRadius: leftOrRight
            ? BorderRadius.only(
                topLeft: Radius.circular(radius),
                bottomLeft: Radius.circular(radius))
            : BorderRadius.only(
                topRight: Radius.circular(radius),
                bottomRight: Radius.circular(radius)),
      ),
      child: TextButton(
          onPressed: onPressed,
          style: ButtonStyle(
            foregroundColor: MaterialStateProperty.resolveWith(
              (states) {
                if (states.contains(MaterialState.disabled)) {
                  return disabledTextColor ?? Colors.white;
                }
                return textColor ?? Colors.white;
              },
            ),
            backgroundColor: MaterialStateProperty.resolveWith((states) {
              if (states.contains(MaterialState.disabled)) {
                return disabledBackgroundColor ?? Colors.transparent;
              }
              return backgroundColor ?? Colors.transparent;
            }),
            overlayColor: MaterialStateProperty.resolveWith((states) {
              return (textColor ?? Colors.white).withOpacity(0.12);
            }),
            minimumSize: (minWidth == null || minHeight == null)
                ? null
                : MaterialStateProperty.all<Size>(Size(minWidth!, minHeight!)),
            padding: MaterialStateProperty.all<EdgeInsetsGeometry>(padding),
            visualDensity: VisualDensity.compact,
            shape: MaterialStateProperty.all<OutlinedBorder>(
              RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(radius),
              ),
            ),
            side: MaterialStateProperty.all<BorderSide>(side),
          ),
          child: Text(
            text,
            style: TextStyle(fontSize: fontSize),
          )),
    );
  }
}
